package com.urguxxi.springdemo.controller;

import com.urguxxi.springdemo.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

// 注意不能用Restcontroller，那个是用来写接口的，不是用来写页面的
// 这里的Controller是用来渲染页面用到
@Controller
@RequestMapping("/thy")
public class ThyController {

    @GetMapping("index")
    public String index(){
        return "index.html"; //这个return的名字必须和要渲染的模板的名字相同
    }

    @GetMapping("/tab")
    public String table(Model model){
        //将数据发送到模板
        //model用来装渲染到页面上的模板数据
        model.addAttribute("title","Shannon University");
        model.addAttribute("tableName","Students");
//
//        //模拟数据的数据查询
//        //准备模拟数据
        List<User> users = new ArrayList<>();
        users.add(new User("Sunny","18022331616","Shanghai",123123123));
        users.add(new User("Jerry","962826382","NewYork",34668));
        users.add(new User("Jasper","96738732","Texas",344578));
        users.add(new User("Amber","49874458","Seoul",556368));
        users.add(new User("Kelly","3836472","Bangkok",675431145));
        users.add(new User("Barbie","4847442","Washington",655368));


        model.addAttribute("users",users);

        return "table";
    }
}
